<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>	
<%@ include file="/pub/headmeta.jsp" %>
</head>
<body>
	<div class="right-head"><span class="right-head-font"><%
	String classId=request.getParameter("classId");
	request.setAttribute("classId", classId);
	out.print("商品编辑&nbsp;&gt;&nbsp;");
	if("A000".equals(classId)){
		out.print("宝宝营养");
	}else if("B000".equals(classId)){
		out.print("宝宝扮靓");
	}else if("C000".equals(classId)){
		out.print("宝宝用品");
	}else if("D000".equals(classId)){
		out.print("宝宝娱乐");
	} %></span></div>
	
	<form id="queryForm" method="post">
	<div class="term">
		<div class="div1-2">商品状态：</div>	
		<select class="div3" name="q_status" id="q_status"><option value="">-全部-</option><option value="0">编辑</option><option value="1">待审核</option><option value="2">审核并上架</option><option value="4">驳回</option><option value="3">下架</option></select>	
		<div class="div1-2">所属分类：</div>	
		<select class="div3" name="q_classId" id="q_classId"><option value="${classId}">-全部-</option></select>
		<br style="clear:both;" /><br />
		<div class="div1-2">商品名称：</div>
		<div class="div2"><input type="text" name="q_goodsName" id="q_goodsName"/></div>
		<div class="div1-2">年龄段：</div>
		<select class="div3" name="q_ageId" id="q_ageId"><option value="">-全部-</option></select>
		<br style="clear:both;" />
	</div>
	<div class="function-bar">
		<div class="div0"><input  type="button" class="button-bar" value="提交审核" onclick="doSubmit();"/></div>		
		<div class="div0"><input  type="button" class="button-bar" value="删除" onclick="doDel();" ${f:op(ops,'商品编辑管理','删除')}/></div>
		<div class="div0"><input  type="button" class="button-bar" value="新增" onclick="viewAdd();" ${f:op(ops,'商品编辑管理','新增')}/></div>
		<div class="div0"><input  type="button" class="button-bar" value="重置条件" onclick="resetEx(this.form);"/></div>
		<div class="div0"><input  type="button" class="button-bar" value="查询" onclick="setCurPage(1);doQuery();"/></div>		
	</div>	
	</form>
	
	<form id="delForm" method="post">
	<table id="MyTableList" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="table-form">
		<tr align="center" class="STYLE1">
			<th width="5%"><input id="ckAll" type="checkbox" onclick="checkAll(this.checked,'cb');" /></th>
			<th width="5%">序号</th>
			<th width="25%">商品名称</th>
			<th width="15%">图片</th>			
			<th width="15%">年龄段</th>				
			<th width="15%">所属分类</th>		
			<th width="10%">状态</th>	
			<th width="15%">操作</th>
		</tr>
	</table>
	<%@ include file="/pub/pageLink.jsp" %>
	</form>	
</body>
</html>
<script type="text/javascript">
<!--
//自动调用初始化
$(document).ready(function(){	
	//查询
	doQuery();
	
	//填充年龄段
	$.ajax({type : "post", url : "${ctx}/age!getList.action?page=1&pageSize=100", data : '', async : false, success : function callback(txt){   
		var json = $.parseJSON(txt);			
		if (json.code==0) {		
			var objs=json.info;
			for(var i=0;i<objs.length;i++){
				$("#q_ageId").append("<option value='"+objs[i].ageId+"'>"+objs[i].ageArea+"</option>"); 
			}
		}else{
			alert('查询失败！');
		}
	}});
	
	//填充分类
	$.ajax({type : "post", url : "${ctx}/classify!getSelectType.action?id=${classId}", data : '', async : false, success : function callback(txt){   
		var json = $.parseJSON(txt);	
		if (json.code==0) {		
			var objs=json.info;
			for(var i=0;i<objs.length;i++){
				$("#q_classId").append("<option value='"+objs[i].classId+"'>"+objs[i].className+"</option>"); 
			}
		}else{
			alert('查询失败！');
		}
	}});

});
var listData;//记录当前页数据
//查询
function doQuery(){	
	var page=getPage();
	var pageSize=getPageSize();
	var url="${ctx}/goods!getList.action?page="+page+"&pageSize="+pageSize;
	$.post(url, $("#queryForm").serialize() ,function callback(txt){   
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				setRecordCount(json.count);
				listData=json.info;
				createTable(listData,page,pageSize);				
			}else{
				alert('查询失败！');
			}
		}	
	);
	$('#ckAll').attr("checked",false);
}

//删除
function doDel(){
	if(ifCheck('cb')){
		if(confirm('确定要删除选中的记录吗？')){
			var url="${ctx}/goods!remove.action";
			$.post(url, $("#delForm").serialize() ,function callback(txt){   
					var json = $.parseJSON(txt);
					if (json.code==0) {	
						doQuery();			
					}else{
						alert('删除失败！');
					}
				}	
			);			
		}
	}else{
		alert('请先勾选记录！');
	}
}

//提交审核
function doSubmit(){
	if(ifCheck('cb')){
		if(confirm('确定要提交审核选中的记录吗？')){
			var url="${ctx}/goods!updateStatus.action?status=1";
			$.post(url, $("#delForm").serialize() ,function callback(txt){   
					var json = $.parseJSON(txt);
					if (json.code==0) {	
						doQuery();			
					}else{
						alert('提交审核失败！');
					}
				}	
			);			
		}
	}else{
		alert('请先勾选记录！');
	}
}

var ss='编辑,待审核,审核并上架,下架,驳回'.split(',');
//创建表数据
function createTable(objs,page,pageSize){	
	var table=document.getElementById('MyTableList');
	for( var i=table.rows.length-1; i>0; i--){
		table.deleteRow(i); 
	}
	var b=document.createElement("tbody");
	for(var i=0;i<objs.length;i++){
		var obj=objs[i];
		var row=document.createElement("tr");	
		row.align="center";	
		
		var c1=document.createElement("td");	
		if(0==obj.status){
			c1.innerHTML="<input name='cb' type='checkbox' value='"+obj.goodsId+"'/>";
		}else{
			c1.innerHTML="";
		}
		var c2=document.createElement("td");	
		c2.innerHTML=(page-1)*pageSize+i+1;
		var c3=document.createElement("td");	
		c3.innerHTML="<a class='edit-font' href=\"javascript:openWin('"+obj.link+"',800,600,'预览链接');\">"+obj.goodsName+"</a>";	
		c3.title=obj.recommend;
		var c4=document.createElement("td");	
		c4.innerHTML="<img height=\"40\" width=\"40\" src='"+obj.goodsPic+"'/>";
		var c5=document.createElement("td");	
		c5.innerHTML=obj.ageArea;
		var c6=document.createElement("td");	
		c6.innerHTML=obj.className;
		var c7=document.createElement("td");
		c7.innerHTML=ss[obj.status];
		var c8=document.createElement("td");	
		if(0==obj.status){
			c8.innerHTML="<a class='edit-font' href=\"javascript:viewEdit('"+obj.goodsId+"');\" ${f:op(ops,'商品编辑管理','修改')}>编辑</a>";
		}else{
			c8.innerHTML="";
		}
		row.appendChild(c1);
		row.appendChild(c2);
		row.appendChild(c3);
		row.appendChild(c4);
		row.appendChild(c5);
		row.appendChild(c6);
		row.appendChild(c7);
		row.appendChild(c8);
		
		setTdStyle(row);
		b.appendChild(row);
	}
	table.appendChild(b);
}

//进入新增页面
function viewAdd(){
	location.href="${ctx}/goods!viewAdd.action?classId=${classId}";
}
//编辑
function viewEdit(id){
	location.href="${ctx}/goods!viewEdit.action?classId=${classId}&id="+id;
}
//-->
</script>
